home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / password / source / driveinit.c next >
C/C++ Source or Header  |  1993-03-12  |  4KB  |  109 lines

  1. #include <exec/memory.h>
  2. #include <exec/resident.h>
  3. #include <exec/execbase.h>
  4.  
  5. #include <proto/exec.h>
  6.  
  7. __builtin_memcpy(void *, void *, int);
  8.  
  9. /***********************************************/
  10.  
  11. struct InsertResident
  12.    {
  13.       struct Resident *MyResident;
  14.       struct Resident *OldResident;
  15.       ULONG Link;
  16.    };
  17.  
  18. struct MyResident
  19.    {
  20.       struct InsertResident ResArray;
  21.       struct Resident Resident;
  22.    };
  23.  
  24. ULONG PasswordCode(void);
  25. void PasswordCodeEnd(void);
  26.  
  27. /***********************************************/
  28.  
  29. void main(void)
  30.  
  31. {
  32.    struct Resident **ResArray;
  33.    struct ExecBase *SysBase;
  34.    struct MyResident *MyResident;
  35.    ULONG CodeLen;
  36.  
  37. /*   if (*((UBYTE *)0x00bfe001) & 0x80) */
  38.       {
  39.          Disable();
  40.          SysBase=*((struct ExecBase **)4);
  41.          if ((((ULONG)FindResident(SysBase->LibNode.lib_Node.ln_Name))&0x00f80000)==0x00f80000)
  42.             {
  43.                ResArray=(struct Resident **)(SysBase->ResModules);
  44.                while (ResArray)
  45.                   {
  46.                      if (((ULONG)*ResArray)&0x80000000 || !*ResArray)
  47.                         {
  48.                            ResArray=(struct Resident **)(((ULONG)*ResArray)&0x7fffffff);
  49.                         }
  50.                      else
  51.                         {
  52.                            if ((*ResArray)->rt_Pri<=-50)
  53.                               {
  54.                                  CodeLen=(ULONG)PasswordCodeEnd-(ULONG)PasswordCode;
  55.                                  MyResident=AllocMem(sizeof(struct MyResident)+CodeLen,MEMF_CLEAR);
  56.                                  MyResident->Resident.rt_MatchWord=RTC_MATCHWORD;
  57.                                  MyResident->Resident.rt_MatchTag=&MyResident->Resident;
  58.                                  MyResident->Resident.rt_EndSkip=((char *)(MyResident+1))+CodeLen;
  59.                                  MyResident->Resident.rt_Init=MyResident+1;
  60.                                  MyResident->Resident.rt_Flags=RTF_COLDSTART;
  61.                                  MyResident->Resident.rt_Pri=-59;
  62.                                  MyResident->ResArray.MyResident=&MyResident->Resident;
  63.                                  MyResident->ResArray.OldResident=*ResArray;
  64.                                  MyResident->ResArray.Link=0x80000000|(ULONG)(ResArray+1);
  65.                                  *ResArray=(struct Resident *)(((ULONG)MyResident)|0x80000000);
  66.                                  ResArray=NULL;
  67.                                  __builtin_memcpy(MyResident->Resident.rt_Init,PasswordCode,CodeLen);
  68.                                  if (SysBase->LibNode.lib_Version>=37)
  69.                                     {
  70.                                        CacheClearE(MyResident->Resident.rt_Init,CodeLen,CACRF_ClearI);
  71.                                     }
  72.                               }
  73.                            else
  74.                               {
  75.                                  ResArray++;
  76.                               }
  77.                         }
  78.                   }
  79.             }
  80.          else
  81.             {
  82.                if (MyResident=(struct MyResident *)FindResident("alert.hook\xd\xa"))
  83.                   {
  84.                      ResArray=(struct Resident **)(SysBase->ResModules);
  85.                      while (ResArray)
  86.                         {
  87.                            if (((ULONG)*ResArray)&0x80000000 || !*ResArray)
  88.                               {
  89.                                  ResArray=(struct Resident **)(((ULONG)*ResArray)&0x7fffffff);
  90.                               }
  91.                            else
  92.                               {
  93.                                  if (*ResArray==(struct Resident *)MyResident)
  94.                                     {
  95.                                        *ResArray=(struct Resident *)(((ULONG)(ResArray+1))|0x80000000);
  96.                                        ResArray=NULL;
  97.                                     }
  98.                                  else
  99.                                     {
  100.                                        ResArray++;
  101.                                     }
  102.                               }
  103.                         }
  104.                   }
  105.             }
  106.          Enable();
  107.       }
  108. }
  109.